<?php
function view_bckbimbel($config,$param) {
    $db = new db($config);
    $result = $db->query("SELECT * FROM bimbel WHERE 1");
	$desc = $db->query("SELECT * FROM deskripsi WHERE page ='bimbel'");
	$kontak = $db->query("SELECT * FROM kontak WHERE page ='bimbel'");
    $param['bimbel'] = true;
    $param['loggedin'] = true;
    view_backend_header($config, $param);
    //verifikasi isian gunakan javascript
    if (isset($_SESSION['editted'])) {
        echo '<div class="alert alert-warning">'.$_SESSION['editted'].'</div>';
        unset($_SESSION['editted']);
    }
    ?>
	<div>
        <form method="post" action="<?php echo $config['home_url']."backend/edbimbel"?>">
            <div>Deskripsi : <textarea class="descbck" name="descbimbel"><?php echo $desc[0]['deskripsi']; ?></textarea>
            <div><input class="btn" type="submit" value="Ubah" name="ubah" /></div>
        </form>
    </div>
	<h3 onclick="javascript:showHide('foto');">Slide++</h3>
	<div id="foto" style="display:none">
		<form action="<?php echo $config['home_url']."backend/edbimbelfoto"?>" method="post" enctype="multipart/form-data">
			<div>Gambar : <input type='file' name='gambar'/></div>
			<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
		</form>
		<div><?php
			$uploaddir = $config['image_path'].'bimbel'.DIRECTORY_SEPARATOR;
			$limitedext = array("jpg","jpeg","png","bmp");
			$cfiles = 0;
			$files = scandir($uploaddir.'pre'.DIRECTORY_SEPARATOR);
			for($i = 0; $i < count($files); $i++) {
				$file = $files[$i];
				$getExt = explode('.',$file);
				$file_ext = $getExt[count($getExt)-1];
				if (in_array($file_ext,$limitedext)) {
					?>
					<div style="float:left">
						<div class='gallery-thumb' id='gallery-thumb-<?php echo $cfiles; ?>' style='max-width:120px;max-height:50px;overflow:hidden;'>
							<img id="gallery-thumb-img-<?php echo $cfiles; ?>" src="<?php echo $config['image_url']."bimbel/pre/".$file; ?>" alt="<?php echo $file; ?>" /></a>
						</div>
						<div align="center">
							<div><a class="ahapus" href="<?php echo $config['home_url']."backend/delbimbelfoto?img=$file"?>">(X)</a></div>
						</div>
					</div>
					<?php
					$cfiles++;
				}
			}
			if ($cfiles<1){
				echo '<div class="judul-gale"><h4>Tidak terdapat slide saat ini</h4></div>';
			}?>
			<div style="clear:both"></div>
		</div>
	</div>
	<h3 onclick="javascript:showHide('kontak');">Kontak</h3>
    <div id="kontak">
        <form method="post" action="<?php echo $config['home_url']."backend/edbimbelkontak"?>">
            <div>No Telp : <input type="text" name="notelp" value="<?php echo $kontak[0]['telp']; ?>" /></div>
            <div>Email : <input type="text" name="email" value="<?php echo $kontak[0]['email']; ?>" /></div>
			<div>Alamat : <textarea class="slimbck" name="alamat"><?php echo $kontak[0]['alamat']; ?></textarea></div>
            <div><input class="btn" type="submit" value="Ubah" name="ubah" /></div>
        </form>
	</div>
    <h3 onclick="javascript:showHide('bimbel');">Kegiatan++</h3>
    <div id="bimbel" style="display:none">
        <form method="post" action="<?php echo $config['home_url']."backend/edbimbelkeg"?>">
            <div>Kegiatan bimbel : <input style="width:400px" type="text" name="kegplus" /></div>
			<div>Deskripsi : <textarea class="descbck" name="descplus"></textarea></div>
            <div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
        </form>
	<div>
			<?php
			echo "<ul>";
			foreach ($result as $res){
				echo "<li><a href=\"javascript:showHide('cs".$res['idBimbel']."');\">".$res['kegiatan']."</a> <a href=\"".$config['home_url']."backend/delbimbelkeg/".$res['idBimbel']."\">(X)</a>";
				echo "<div style=\"display:none\"id=\"cs".$res['idBimbel']."\">";
					//echo $config['home_url']."backend/kutipan/".$res['idkutipan'];
					echo "<form method=\"post\" action=\"".$config['home_url']."backend/edbimbelkeg"."\">";
						echo "<input type=\"hidden\" name=\"id\" value=\"".$res['idBimbel']."\" />";
						echo "<div>Kegiatan bimbel : <input style=\"width:400px\" type=\"text\" name=\"keged\" value=\"".$res['kegiatan']."\" /></div>";
						echo "<div>Deskripsi : <textarea class=\"descbck\" name=\"desced\">".$res['deskripsi']."</textarea></div>";
						echo "<div><input class=\"btn\" type=\"submit\" value=\"Edit\" name=\"edit\" /></div>";
					echo "</form>";
				?>
					<h4 onclick="javascript:showHide('subk<?php echo $res['idBimbel']; ?>');">Sub++</h4>
					<div id="subk<?php echo $res['idBimbel']; ?>" style="display:none">
						<form method="post" action="<?php echo $config['home_url']."backend/edbimbelsub"?>">
							<input type="hidden" name="idKeg" value="<?php echo $res['idBimbel']; ?>" />
							<div>Sub Kegiatan : <input style="width:400px" type="text" name="subplus" /></div>
							<div>Deskripsi : <textarea class="descbck" name="descplus"></textarea></div>
							<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
						</form>
					<div>
					<?php
					echo "<ul>";
						$hasils = $db->query("SELECT * FROM sub_bimbel WHERE idBimbel = ".$res['idBimbel']);
						foreach ($hasils as $hasil) {
							echo "<li><a href=\"javascript:showHide('subb".$hasil['idSubbimbel']."');\">".$hasil['subb']."</a> <a href=\"".$config['home_url']."backend/delbimbelsub/".$res['idBimbel']."/".$hasil['idSubbimbel']."\">(X)</a>";
							echo "<div style=\"display:none\"id=\"subb".$hasil['idSubbimbel']."\">";
								echo "<form method=\"post\" action=\"".$config['home_url']."backend/edbimbelsub"."\">";
									echo "<input type=\"hidden\" name=\"id\" value=\"".$hasil['idSubbimbel']."\" />";
									echo "<div>Kegiatan bimbel : <input style=\"width:400px\" type=\"text\" name=\"subed\" value=\"".$hasil['subb']."\" /></div>";
									echo "<div>Deskripsi : <textarea class=\"descbck\" name=\"desced\">".$hasil['desc']."</textarea></div>";
									echo "<div><input class=\"btn\" type=\"submit\" value=\"Edit\" name=\"edit\" /></div>";
								echo "</form>";
						?>
							<h4 onclick="javascript:showHide('foto<?php echo $hasil['idSubbimbel']; ?>');">Foto++</h4>
							<div id="foto<?php echo $hasil['idSubbimbel']; ?>" style="display:none">
								<form action="<?php echo $config['home_url']."backend/addbimbelkegfoto"?>" method="post" enctype="multipart/form-data">
									<input type="hidden" name="idk" value="<?php echo $res['idBimbel']; ?>" />
									<input type="hidden" name="ids" value="<?php echo $hasil['idSubbimbel']; ?>" />
									<div>Gambar : <input type='file' name='gambar'/></div>
									<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
								</form>
								<div><?php
									$uploaddir = $config['image_path'].'bimbel'.DIRECTORY_SEPARATOR."pre-foto".DIRECTORY_SEPARATOR;
									$cfiles = 0;
									$regex = $uploaddir.$res['idBimbel']."-".$hasil['idSubbimbel']."-*";
									$limitedext = array("jpg","jpeg","png","bmp");
									//FILTER
									foreach (glob($regex) as $files) {
										$getFile = explode(DIRECTORY_SEPARATOR,$files);
										$file = $getFile[count($getFile)-1];
										$getExt = explode('.',$file);
										$file_ext = $getExt[count($getExt)-1];
										if (in_array($file_ext,$limitedext)) {
											?>
											<div style="float:left">
												<div class='gallery-thumb' id='gallery-thumb-<?php echo $cfiles; ?>' style='max-width:80px;max-height:50px;overflow:hidden;'>
													<img id="gallery-thumb-img-<?php echo $cfiles; ?>" src="<?php echo $config['image_url']."bimbel/pre-foto/".$file; ?>" alt="<?php echo $file; ?>" /></a>
												</div>
												<div align="center">
													<div><a class="ahapus" href="<?php echo $config['home_url']."backend/delbimbelkegfoto?img=$file"?>">(X)</a></div>
												</div>
											</div>
											<?php
											$cfiles++;
										}
									}
									if ($cfiles<1){
										echo '<div class="judul-gale"><h5>Tidak terdapat foto saat ini</h5></div>';
									}?>
									<div style="clear:both"></div>
								</div>
							</div>
						<?php
						echo "</div></li>";
						}
					echo "</ul>";
					?>
				<?php
				echo "</div></li>";
			}
			echo "</ul>";
			?>
		</div>
	</div>
	<h3 onclick="javascript:showHide('download');">Download</h3>
	<div id="download">
		<div><?php
			$uploaddir = $config['image_path'].'bimbel'.DIRECTORY_SEPARATOR;
			$cfiles = 0;
			$regex = $uploaddir."download.*";
			//FILTER
			foreach (glob($regex) as $files) {
				$getFile = explode(DIRECTORY_SEPARATOR,$files);
				$file = $getFile[count($getFile)-1];
				?>
				<div id='download-thumb-<?php echo $cfiles; ?>'>
					<a id="download-thumb-img-<?php echo $cfiles; ?>" href="<?php echo $config['image_url']."bimbel/".$file; ?>" alt="<?php echo $file; ?>" /><?php echo $file; ?></a> <a class="ahapus" href="<?php echo $config['home_url']."backend/delbimbeldl?file=$file"?>">(X)</a>
				</div>
				<?php
				$cfiles++;
				break;
			}
			if ($cfiles<1){
				echo '<div class="judul-gale"><h4>Tidak terdapat file saat ini</h4></div>';
				?>
				<form action="<?php echo $config['home_url']."backend/edbimbeldl"?>" method="post" enctype="multipart/form-data">
					<div>File : <input type='file' name='unduh'/></div>
					<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
				</form>
			<?php } ?>
		</div>
	</div>
    <?php
    view_backend_footer($config, $param);
}
